package com.wgy.day27.斗地主综合案例有序;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

public class DouDiZhu02 {
    public static void main(String[] args) {
        //1.准备牌
        //创建一个Map集合,存储牌的索引和组装好的牌
        HashMap<Integer, String> poker = new HashMap<>();
        //创建一个list集合,存储牌的索引
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        //定义两个集合,存储花色和牌的字号
        List<String> colors = List.of("♥", "♠", "♣", "♦");
        List<String> numbers = List.of("2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3");
        //把大王小王存储到poker集合中
        int index = 0;
        poker.put(index, "大王");
        pokerIndex.add(index);
        index++;
        poker.put(index, "小王");
        pokerIndex.add(index);
        index++;
        //循环嵌套遍历2个集合,组装52张牌,存储到poker集合中
        for (String color : colors) {
            for (String number : numbers) {
                poker.put(index, number + color);
                pokerIndex.add(index);
                index++;
            }
        }

        //2.洗牌 使用Collections的shuffle方法
        Collections.shuffle(pokerIndex);

        //3.发牌
        ArrayList<Integer> player01 = new ArrayList<>();
        ArrayList<Integer> player02 = new ArrayList<>();
        ArrayList<Integer> player03 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();
        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer n = pokerIndex.get(i);
            if (i >= 51) {
                diPai.add(n);
            } else if (i % 3 == 1) {
                player01.add(n);
            } else if (i % 3 == 2) {
                player02.add(n);
            } else if (i % 3 == 0) {
                player03.add(n);
            }
        }

        //4.排序 使用Collections集合中发sort方法
        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(diPai);

        //5.看牌
        lookPoker("刘德华",poker,player01);
        lookPoker("周润发",poker,player02);
        lookPoker("周星驰",poker,player03);
        lookPoker("底牌",poker,diPai);
    }
      // 定义一个看牌的方法
    public static void lookPoker(String name,HashMap<Integer,String> poker,ArrayList<Integer> list){
        System.out.print(name+":    ");
        //遍历玩家或底牌集合,获取牌的索引
        for (Integer key : list) {
            String value = poker.get(key);
            System.out.print(value+"");
        }
        System.out.println();
    }
}
